using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Game;
using IQIGame.Onigao.GameAOT;

namespace IQIGame.Onigao.GamePlay
{
    public class UIFriend_Search : UIBaseNode
    {
        #region Template Generate,don't modify
        protected class UIB_UIFriend_Search
        {
            #region ObjectBinding Generate
            public UnityEngine.GameObject search { protected set; get; }
            public UnityEngine.GameObject showPanel { protected set; get; }
            public IQIGame.Onigao.Framework.ExButton btnReturn { protected set; get; }
            public virtual void InitBinding(ObjectBinding __binding)
            {
                __binding.TryGetVariableValue<UnityEngine.GameObject>("search", out var __tbv0);
                this.search = __tbv0;
                __binding.TryGetVariableValue<UnityEngine.GameObject>("showPanel", out var __tbv1);
                this.showPanel = __tbv1;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExButton>("btnReturn", out var __tbv2);
                this.btnReturn = __tbv2;
            }
            #endregion ObjectBinding Generate 
        }
        #endregion Template Generate,don't modify



        #region fields
        public UISearchPanel uISearchPanel = null;
        public UIShowPanel uIShowPanel = null;


        #endregion fields
        #region properties


        protected UIB_UIFriend_Search ui { get; set; }
        protected UIMsgDispatcher uiMsgDispatcher => this._msgDispatcher as UIMsgDispatcher;
        #endregion properties

        protected override void BeforeInit()
        {
            ui = new UIB_UIFriend_Search();
            ui.InitBinding(this.csObjBind);
        }

        protected override void OnInit()
        {
            uIShowPanel = InitChildNode<UIShowPanel>(this.ui.showPanel);
            uISearchPanel = InitChildNode<UISearchPanel>(this.ui.search);

        }



        protected override void OnShow()
        {

            uIShowPanel.Hide();
            uISearchPanel.Show();
        }

        protected override void OnHide()
        {

        }



        /// <summary>
        /// 添加UGUI侦听
        /// </summary>
        protected override void AddUGUIListener()
        {
            this.ui.btnReturn.AddClickEvent(OnClickReturn);
        }



        /// <summary>
        /// 添加全局侦听（MsgDispatcher）
        /// </summary>
        protected override void AddMsgListeners()
        {
            uiMsgDispatcher.AddListener(MsgEventType.SearchChanged, OnSearchChanged);

        }

        protected override void OnDispose()
        {

        }




        #region methonds
        private void OnClickReturn()
        {
            this.uIShowPanel.Hide();
            this.uISearchPanel.Show();
        }
        private void OnSearchChanged()
        {
            this.uISearchPanel.Hide();
            this.uIShowPanel.Show();

            this.uIShowPanel.RefillCells();

        }
        #endregion methonds
    }
}